﻿using Coldairarrow.Business.MEGA;
using Coldairarrow.Entity.MEGA;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.MEGA
{
    [Route("/MEGA/[controller]/[action]")]
    public class MEGA_WorkerController : BaseApiController
    {
        #region DI

        public MEGA_WorkerController(IMEGA_WorkerBusiness mEGA_WorkerBus)
        {
            _mEGA_WorkerBus = mEGA_WorkerBus;
        }

        IMEGA_WorkerBusiness _mEGA_WorkerBus { get; }

        #endregion

        #region 获取
        /// <summary>
        /// 获取员工列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>

        [HttpPost]
        public async Task<PageResult<MEGA_Worker>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _mEGA_WorkerBus.GetDataListAsync(input);
        }

        /// <summary>
        /// 获取员工列表详情
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<MEGA_Worker> GetTheData(IdInputDTO input)
        {
            return await _mEGA_WorkerBus.GetTheDataAsync(input.id);
        }

        #endregion

        #region 提交

        /// <summary>
        /// 员工信息新增、删除
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task SaveData(MEGA_Worker data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _mEGA_WorkerBus.AddDataAsync(data);
            }
            else
            {
                await _mEGA_WorkerBus.UpdateDataAsync(data);
            }
        }
        /// <summary>
        /// 单条删除、批量删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _mEGA_WorkerBus.DeleteDataAsync(ids);
        }

        #endregion
    }
}